import base64
import cv2
import numpy as np


def standard_ocr_result(ocr_result):

    positions_text = []
    for i in range(len(ocr_result)):
        pos_text = []
        for box in ocr_result[i]["pos"]:
            pos_text.extend(box)
        pos_text.append(ocr_result[i]["text"])

        positions_text.append(pos_text)
    return positions_text

def input_pipeline(ocr_result):
    input_images = ocr_result["image"]
    input_json = ocr_result['text']
    orc_standard_result = standard_ocr_result(input_json)
    file_name = ocr_result["filename"]

    input_images = base64.b16decode(input_images.encode("ascii"))
    image_data = np.frombuffer(input_images,np.un)
    image_data = cv2.imdecode(image_data,cv2.IMREAD_COLOR)
    return file_name,image_data,orc_standard_result